package com.yczlab.mybatis.controller;

import com.yczlab.mybatis.entity.Employee;
import com.yczlab.mybatis.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("emp/")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    @GetMapping("/findOne")
    @ResponseBody
    public Employee findById(@RequestParam("id") int employeeId) {
        Employee employee = employeeService.findById(employeeId);
        return employee;
    }

    @GetMapping("/findAll")
    @ResponseBody
    public List<Employee> findAll() {
        List<Employee> allEmployees = employeeService.findAll();
        return allEmployees;
    }
}
